home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / src / specfunc / elementary.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-04-18  |  2.5 KB  |  87 lines

  1. /* specfunc/elementary.c
  2.  * 
  3.  * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
  4.  * 
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or (at
  8.  * your option) any later version.
  9.  * 
  10.  * This program is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * General Public License for more details.
  14.  * 
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. /* Author:  G. Jungman */
  21.  
  22. #include <config.h>
  23. #include <gsl/gsl_math.h>
  24. #include <gsl/gsl_errno.h>
  25. #include <gsl/gsl_sf_elementary.h>
  26.  
  27. #include "error.h"
  28. #include "check.h"
  29.  
  30. int
  31. gsl_sf_multiply_e(const double x, const double y, gsl_sf_result * result)
  32. {
  33.   const double ax = fabs(x);
  34.   const double ay = fabs(y);
  35.  
  36.   if(x == 0.0 || y == 0.0) {
  37.     /* It is necessary to eliminate this immediately.
  38.      */
  39.     result->val = 0.0;
  40.     result->err = 0.0;
  41.     return GSL_SUCCESS;
  42.   }
  43.   else if((ax <= 1.0 && ay >= 1.0) || (ay <= 1.0 && ax >= 1.0)) {
  44.     /* Straddling 1.0 is always safe.
  45.      */
  46.     result->val = x*y;
  47.     result->err = 2.0 * GSL_DBL_EPSILON * fabs(result->val);
  48.     return GSL_SUCCESS;
  49.   }
  50.   else {
  51.     const double f = 1.0 - 2.0 * GSL_DBL_EPSILON;
  52.     const double min = GSL_MIN_DBL(fabs(x), fabs(y));
  53.     const double max = GSL_MAX_DBL(fabs(x), fabs(y));
  54.     if(max < 0.9 * GSL_SQRT_DBL_MAX || min < (f * DBL_MAX)/max) {
  55.       result->val = GSL_COERCE_DBL(x*y);
  56.       result->err = 2.0 * GSL_DBL_EPSILON * fabs(result->val);
  57.       CHECK_UNDERFLOW(result);
  58.       return GSL_SUCCESS;
  59.     }
  60.     else {
  61.       OVERFLOW_ERROR(result);
  62.     }
  63.   }
  64. }
  65.  
  66.  
  67. int
  68. gsl_sf_multiply_err_e(const double x, const double dx,
  69.                          const double y, const double dy,
  70.                          gsl_sf_result * result)
  71. {
  72.   int status = gsl_sf_multiply_e(x, y, result);
  73.   result->err += fabs(dx*y) + fabs(dy*x);
  74.   return status;
  75. }
  76.  
  77.  
  78. /*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
  79.  
  80. #include "eval.h"
  81.  
  82. double gsl_sf_multiply(const double x, const double y)
  83. {
  84.   EVAL_RESULT(gsl_sf_multiply_e(x, y, &result));
  85. }
  86.  
  87.